package com.wy.authority.service.impl;

import com.wy.authority.entity.Procurement;
import com.wy.authority.mapper.ProcurementMapper;
import com.wy.authority.service.ProcurementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author 忘忧
 * @Date Created in 2021/2/1 15:13
 * @Description:
 */
@Service
public class ProcurementServiceImpl implements ProcurementService {
    @Autowired
    private ProcurementMapper procurementMapper;

    @Override
    public List<Procurement> findall() {
        return procurementMapper.findall();
    }

    @Override
    public List<Procurement> findbyid(int proc_id) {
        return null;
    }

    @Override
    @Transactional
    public Procurement find_bynum(Integer pagenum, Integer pagesize) {
        Procurement procurement = new Procurement();
        //默认从O开始
        if(pagenum !=null && pagesize !=null){
            pagenum =(pagenum-1)*pagesize;
        }
        //获取当前信息
        List<Procurement> procurements  =procurementMapper.find_bynum(pagenum,pagesize);
        procurement.setData(procurements);
        //获取当前总量
        Long total =procurementMapper.gettotal();
        procurement.setTotal(total);

        return procurement;
    }


    @Override
    public Long gettotal() {
        return procurementMapper.gettotal();
    }

    @Override
    public int insert(Procurement procurement) {

        return procurementMapper.insert(procurement);
    }

    @Override
    public int update(Procurement procurement) {
        int proc_num =procurement.getProc_num();
        double proc_price =procurement.getProc_price();
        double total_price=proc_num*proc_price;
        procurement.setTotal_price(total_price);
        return procurementMapper.update(procurement);
    }

    @Override
    public int update2(Procurement procurement) {
        return procurementMapper.update2(procurement);
    }

    @Override
    public int delete(int pro_id) {
        return procurementMapper.delete(pro_id);
    }

    @Override
    public List<Procurement> selectby_ord(String search, String type, String people) {
        return procurementMapper.selectby_ord(search,type ,people);
    }
}
